//
//  Address_Manager_Controller.m
//  pmmSS
//
//  Created by Mac book on 2017/9/21.
//  Copyright © 2017年 WTFSSD. All rights reserved.
//

#import "Address_Manager_Controller.h"

#import "NewAddressCell.h"
#import "add_addressController.h"
@interface Address_Manager_Controller ()<UITableViewDelegate,UITableViewDataSource,NewAddressCellDelegate>

@property (nonatomic,strong) UITableView *tableView;


@end

@implementation Address_Manager_Controller

-(void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];

    [self setUpNavBar];

}
-(void)viewDidLoad{

    [super viewDidLoad];

    [self createTableView];

}
-(void)setUpNavBar{


    UILabel *title_label = [HMLabel createLabelWithText:@"我的地址" andTextColor:[UIColor whiteColor] andBgColor:nil andFont:[UIFont fontWithName:default_fontname size:autoScaleW(20)] andTextAlignment:NSTextAlignmentCenter];
    title_label.frame = CGRectMake(0, 0, 100, 35);

    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"nav_bgimage"] forBarMetrics:UIBarMetricsDefault];

    self.navigationItem.titleView = title_label;


    UIButton *leftBtn = [HMButton createButtonWithTitle:nil andTitleColor:nil andBgColor:nil andImage:[UIImage imageNamed:@"icon_arrow_left_white"] andBgImage:nil andSelecter:@selector(clickButton:) andTarget:self andTag:101];
    leftBtn.frame = CGRectMake(0, 0, autoScaleW(60), autoScaleW(30));
    [leftBtn setImageEdgeInsets:UIEdgeInsetsMake(autoScaleH(7), 0, autoScaleH(7), autoScaleW(50))];

    UIBarButtonItem *leftItem = [[UIBarButtonItem alloc]initWithCustomView:leftBtn];

    [self.navigationItem setLeftBarButtonItem:leftItem];

    
}
-(void)createTableView{

    _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, GET_FRAME_WIDTH(self.view), GET_FRAME_HEIGHT(self.view) - 64 - autoScaleH(50)) style:UITableViewStylePlain];

    _tableView.backgroundColor = View_BackgroundColor;
    _tableView.rowHeight = autoScaleH(115);
    _tableView.delegate = self ;
    _tableView.dataSource = self;

    [self.view addSubview:_tableView];

    // TODO : 新增地址

    WeakSelf(weakSelf);

    UIButton *address_btn = [HMButton createButtonWithTitle:@"添加地址" andTitleColor:[UIColor whiteColor] andBgColor:nil andImage:nil andBgImage:[UIImage imageNamed:@"nav_bgimage"] andSelecter:@selector(clickButton:) andTarget:self andTag:102];

    address_btn.titleLabel.font = [UIFont fontWithName:default_fontname size:autoScaleW(14)];


    [self.view addSubview:address_btn];

    [address_btn mas_makeConstraints:^(MASConstraintMaker *make) {

        make.left.mas_equalTo(0);
        make.right.mas_equalTo(0);
        make.top.equalTo(weakSelf.tableView.mas_bottom).offset(0);
        make.width.mas_equalTo(GET_FRAME_WIDTH(weakSelf.view));
        make.height.mas_equalTo(autoScaleH(50));
        
    }];

    [_tableView registerClass:[NewAddressCell class] forCellReuseIdentifier:@"NewAddressCell"];

}

#pragma mark : UITableViewDelegate,UITableViewDataSource


-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{

    return 5 ;

}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    return 1;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{


    static NSString * ceelId  =  @"NewAddressCell";

    NewAddressCell * cell = [tableView dequeueReusableCellWithIdentifier:ceelId ];

    cell.delegate = self;

    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return  cell;

}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{


}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{

    return autoScaleH(10);
}

-(void)clickButton:(UIButton *)button{

    switch (button.tag) {
        case 101:
        {
          [self.navigationController popViewControllerAnimated:YES];

        }
            break;
        case 102:
        {

            add_addressController * vc = [[add_addressController alloc] init];

            [self.navigationController pushViewController:vc animated:YES];

        }
            break;

        default:
            break;
    }


}

#pragma  mark : NewAddressCellDelegate
-(void)passButtonTag:(NSInteger)buttonTag{

   
       NSLog(@" buttonTag === %ld ",buttonTag);

}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
